package cn.com.yusys.yusp.mobile.service;

import cn.com.yusys.yusp.commons.mapper.CommonMapper;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.mobile.repository.mapper.WcrmCustViewInfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhoukanghui
 * @version 1.0
 * @date 2021/8/6 16:17
 */
@Service
public class WcrmCustViewInfoService extends CommonService {

    @Resource
    private WcrmCustViewInfoMapper custViewInfoMapper;

    @Override
    protected CommonMapper getMapper() {
        return null;
    }

    /**
     * 客户基础信息查询
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> selectCustBaseInfo(QueryModel queryModel){
        return custViewInfoMapper.selectCustBaseInfo(queryModel);
    }

    /**
     * 客户时间轴
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> queryTimeAxs(QueryModel queryModel){
        return custViewInfoMapper.queryTimeAxs(queryModel);
    }

    /**
     * 对外投资
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> queryOutInvest(QueryModel queryModel){
        return custViewInfoMapper.queryOutInvest(queryModel);
    }

    /**
     * 资金流向
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> queryMoneyFlow(QueryModel queryModel){
        return custViewInfoMapper.queryMoneyFlow(queryModel);
    }

    /**
     * 担保关系
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> querygurtInfo(QueryModel queryModel){
        return custViewInfoMapper.querygurtInfo(queryModel);
    }

    /**
     * 家庭关系
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> queryfamyInfo(QueryModel queryModel){
        return custViewInfoMapper.queryfamyInfo(queryModel);
    }

    /**
     * 客户资产负债
     * @param queryModel
     * @return
     */
    public Map<String,Object> queryAstLby(QueryModel queryModel){
        Map<String,Object> map =new HashMap<>(5);
        List<Map<String,Object>> hqList= custViewInfoMapper.queryAstLbyHq(queryModel);
        List<Map<String,Object>> dqList= custViewInfoMapper.queryAstLbyDq(queryModel);
        List<Map<String,Object>> dkList= custViewInfoMapper.queryAstLbyDk(queryModel);
        List<Map<String,Object>> lcList= custViewInfoMapper.queryAstLbyLc(queryModel);
        List<Map<String,Object>> jjList= custViewInfoMapper.queryAstLbyJj(queryModel);
        map.put("hqck",hqList);
        map.put("dqck",dqList);
        map.put("dk",dkList);
        map.put("lc",lcList);
        map.put("jj",jjList);
        return map;
    }

    /**
     * 客户签约
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> querySignInfo(QueryModel queryModel){
        return custViewInfoMapper.querySignInfo(queryModel);
    }

    /**
     * 逾欠信息
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> queryOverOwing(QueryModel queryModel){
        List<Map<String, Object>> checkBjNm = custViewInfoMapper.checkBj(queryModel);
        List<Map<String, Object>> checkLxNm = custViewInfoMapper.checkLx(queryModel);
        List<Map<String,Object>> overOwingInfo = new ArrayList<>();
        if(Integer.parseInt(checkBjNm.get(0).get("yqNm").toString())>0){
            List<Map<String, Object>> bjNotSettle = custViewInfoMapper.BjNotSettle(queryModel);
            overOwingInfo.add(bjNotSettle.get(0));
        }else{
            List<Map<String, Object>> bjSettle = custViewInfoMapper.BjSettle(queryModel);
            overOwingInfo.add(bjSettle.get(0));
        }
        if(Integer.parseInt(checkLxNm.get(0).get("yqNm").toString())>0){
            List<Map<String, Object>> lxNotSettle = custViewInfoMapper.lxNotSettle(queryModel);
            overOwingInfo.add(lxNotSettle.get(0));
        }else{
            List<Map<String, Object>> lxSettle = custViewInfoMapper.lxSettle(queryModel);
            overOwingInfo.add(lxSettle.get(0));
        }
        return overOwingInfo;
    }


    /**
     * 预警信息
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> queryearlyWarn(QueryModel queryModel){
        return custViewInfoMapper.queryearlyWarn(queryModel);
    }

    /**
     * 黑名单信息
     * @param queryModel
     * @return
     */
    public List<Map<String,Object>> queryblklist(QueryModel queryModel){
        return custViewInfoMapper.queryblklist(queryModel);
    }

    /**
     * 编辑客户部分信息
     * @param queryModel
     * @return
     */
    @Transactional
    public Integer saveCustInfo(QueryModel queryModel){
        return custViewInfoMapper.saveCustInfo(queryModel);
    }
}
